using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class WorkflowTemplateMap : EntityTypeConfiguration<WorkflowTemplate>
	{
		public WorkflowTemplateMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.NameValue)
				.HasMaxLength(100);
				
			// Table & Column Mappings
			this.ToTable("WorkflowTemplates");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.SeqOrder).HasColumnName("SeqOrder");
			this.Property(t => t.EmployeeId).HasColumnName("EmployeeId");
			this.Property(t => t.NameValue).HasColumnName("NameValue");
			this.Property(t => t.WorkflowTemplateMasterId).HasColumnName("WorkflowTemplateMasterId");
			this.Property(t => t.WorkflowApprovalTypeId).HasColumnName("WorkflowApprovalTypeId");

			// Relationships
			this.HasOptional(t => t.Employee)
				.WithMany(t => t.WorkflowTemplates)
				.HasForeignKey(d => d.EmployeeId);
				
			this.HasOptional(t => t.WorkflowApprovalType)
				.WithMany(t => t.WorkflowTemplates)
				.HasForeignKey(d => d.WorkflowApprovalTypeId);
				
			this.HasOptional(t => t.WorkflowMasterTemplate)
				.WithMany(t => t.WorkflowTemplates)
				.HasForeignKey(d => d.WorkflowTemplateMasterId);
				
		}
	}
}

